package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {

    private CheckBox cb_1;
    private CheckBox cb_2;
    private CheckBox cb_3;
    private Button btn_send;
    private ImageView img_pgbar;
    private AnimationDrawable ad;
    private SeekBar sb_normal;
    private TextView txt_cur;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        单选按钮的触发吐司事件
//        RadioGroup radioGroup =(RadioGroup)findViewById(R.id.radiogroup);
//
//        radioGroup.setOnHierarchyChangeListener(new OnCheckedChangeListener(){
//
//            @Override
//            public void onCheckedChanged(RadioGroup group, int checkedId) {
//                RadioButton radioButton =(RadioButton)findViewById(checkedId);
//                Toast.makeText(getApplicationContext(),"按钮组值改变，你选择了"+radioButton.getText(),Toast.LENGTH_LONG).show();
//            }
//        });

//复选框的连接
        cb_1=(CheckBox)findViewById(R.id.cb_1);
        cb_2=(CheckBox)findViewById(R.id.cb_2);
        cb_3=(CheckBox)findViewById(R.id.cb_3);
        btn_send=(Button)findViewById(R.id.btn_send);

        cb_1.setOnClickListener(this);
        cb_2.setOnClickListener(this);
        cb_3.setOnClickListener(this);
        btn_send.setOnClickListener(this);

        //正在加载的进度条  逐帧动画
        img_pgbar =(ImageView)findViewById(R.id.img_bgbar);
        ad=(AnimationDrawable)img_pgbar.getDrawable();
        img_pgbar.postDelayed(new Runnable() {
            @Override
            public void run() {
                ad.start();
            }
        },100);



        //拖动条
        mContext =MainActivity.this;
        bindViews();
    }

    private void bindViews() {

        sb_normal = (SeekBar) findViewById(R.id.sb);
        txt_cur = (TextView) findViewById(R.id.text_sb);
        sb_normal.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                txt_cur.setText("当前进度值:" + progress + "  / 100 ");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(mContext, "触碰SeekBar", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(mContext, "放开SeekBar", Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    public void onClick(View v) {
        String choose="";
//        Integer num=0;
        if(cb_1.isChecked()){
            choose+=cb_1.getText().toString()+"";
//            num+=1;
        }
        if(cb_2.isChecked()){
            choose+=cb_2.getText().toString()+"";
//            num+=1;
        }
        if(cb_3.isChecked()){
            choose+=cb_3.getText().toString()+"";
//            num+=1;
        }
        Toast.makeText(this,choose,Toast.LENGTH_SHORT).show();
//        Toast.makeText(this,num,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(buttonView.isChecked()){
            Toast.makeText(this,buttonView.getText().toString(),Toast.LENGTH_SHORT).show();
        }
    }
}